package com.kw.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kw.drug.entity.Owinfo;
import com.kw.drug.mapper.OwinfoMapper;
import com.kw.drug.service.OwinforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OwinfoServiceImpl implements OwinforService {
    @Autowired
    OwinfoMapper owinfoMapper;

    @Override
    public IPage<Owinfo> selectOwinfoPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Owinfo> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(param)) {
            queryWrapper.like("dname", param);
        }
        Page<Owinfo> page = new Page<>(pageNum, pageSize);
        return owinfoMapper.selectPage(page, queryWrapper);
    }


    /**
     * 修改一条药品出入库信息
     *
     * @param owinfo
     */
    @Override
    public int editOwinfo(Owinfo owinfo) {
        return owinfoMapper.updateById(owinfo);
    }

    /**
     * 根据主键id查询一个药品出入库对象
     *
     * @param id
     * @return
     */
    @Override
    public Owinfo queryOwinfoById(Integer id) {
        return owinfoMapper.selectById(id);
    }

    /**
     * 根据一个id删除商品出入库
     */
    @Override
    public Integer deleteOwinfoById(Integer id) {

        int count = owinfoMapper.deleteById(id);
        return count;
    }

    @Override
    public Integer owinfoAdd(Owinfo owinfo) {
        int count = owinfoMapper.insert(owinfo);
        return count;
    }
}
